// 定义构造函数
function Person() {
    this.name = 'zhichao'
    this.sex = 'nan'
}
Person.prototype.say = function (msg) {
    console.log('说话：', msg)
}
let p1 = new Person()
p1.say('123')



class PersonC {
    name = 'zhichao'
    sex = 'nan'
    say(msg) {
        console.log(`个人信息:${this.name}:${this.sex}`)
        console.log('说话：', msg)
    }
}

let pc12 = new PersonC()
console.log(pc12.name)
console.log(pc12.sex)
pc12.say('123')


class PersonC1 {
    name
    sex
    constructor(name, sex) {
        // 构造函数接受到值后，对类属性进行初始化
        console.log('new 对象的时候调用')
        this.name = name
        this.sex = sex
    }
    say(msg) {
        console.log(`个人信息:${this.name}:${this.sex}`)
        console.log('说话：', msg)
    }
}

// 初始化对象，调用构造函数 constructor
// 把'zhichao','nan' 传给 构造函数的形参
let pc1 = new PersonC1('zhichao', 'nan')
console.log(pc1.name)
console.log(pc1.sex)

let pc2 = new PersonC1('cuimengjiao', 'nv')
console.log(pc2.name)
console.log(pc2.sex)



// 处理复杂的赋值结构，
// 当构造函数中需要赋值的属性比较多的时候，
// 可以采用【解构+传对象】的方式简化赋值

// class PersonCMult {
//     name
//     sex
//     birthday
//     shenfengzheng

//     constructor(user) {
//         console.log('new')
//             // this.name = user.name
//             // this.sex = user.sex
//             // this.birthday = user.birthday
//             // this.shenfengzheng = user.shenfengzheng

//             ({
//                 name: this._name,
//                 sex: this.sex,
//                 birthday: this.birthday,
//                 shenfenzheng: this.shenfenzheng,
//             } = user)

//     }



// }
// let userobj1 = {
//     name: 'chao00000',
//     sex: 'nan',
//     birthday: '2002-12-12',
//     shenfenzheng: '2343253535422524',
// }
// let pcm1 = new PersonCMult(userobj1)



// class Foo {
//     #a;
//     #b;
//     constructor(a, b) {
//         this.#a = a;
//         this.#b = b;
//     }
//     #sum() {
//         return this.#a + this.#b;
//     }
//     printSum() {
//         console.log(this.#sum())
//     }
// }
// let fooObj1 = new Foo('apple', 'fuck')
// fooObj1.printSum()



// class MyClass {
//     constructor() {
//     }
//     get names() {
//         return '123';
//     }
//     set names(value) {
//         console.log('123' + value)
//     }
// }
// let inst = new MyClass()

// inst.names
// inst.names = 123;


class Foo {
    #a
    #b
    constructor(a, b) {
        this.#a = a;
        this.#b = b;
    }
    #sum() {
        return this.#a + this.#b;
    }
    printSum() {
        console.log(this.#sum());
    }
    get a() {
        return this.#a;
    }
    set a(value) {
        this.#a = value;
    }
    get b() {
        return this.#b;
    }
    set b(value) {
        this.#b = value;
    }
}

let fooObj1 = new Foo('apple', 'fuck')
console.log(fooObj1.a)
console.log(fooObj1.b)
console.log('-----------------------------')

fooObj1.a = 'bananan'
fooObj1.b = 'cao'
console.log(fooObj1.a)
console.log(fooObj1.b)




